package news.controller;

import news.service.AddPublishServiceImpl;
import news.service.IAddPublishService;
import news.util.BaseHttpServlet;
import news.util.FileUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author JiangJ
 * @date 2022/3/4 17:09
 */
@WebServlet("/addPublishRes")
public class AddPublishResController extends BaseHttpServlet {
    IAddPublishService iAddPublishService=new AddPublishServiceImpl();
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 设置响应内容类型
        response.setContentType("text/html;charset=UTF-8");
        request.setCharacterEncoding("utf-8");
        //获取数据
        //todo 获取新闻id
//        int newsid = 0;
//        String type = request.getParameter("theme");、

        //文件上传，将得到得路径存储至数据库
        String filePath = FileUtils.filesUpload(request, response);
        //存储文件路径
        iAddPublishService.addNewsRes(filePath);
        //跳转至分页页面
        request.getRequestDispatcher(request.getContextPath() + "/news/main/news_content.jsp").forward(request, response);

    }
}
